home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / docs / asm_guide / examples / playfield demo.s < prev    next >
Text File  |  1992-03-28  |  5KB  |  190 lines

  1.     incdir    df0:include/
  2.     include exec/exec_lib.i
  3.     include exec/memory.i
  4.     include hardware/custom.i
  5.     include graphics/graphics_lib.i
  6.  
  7. ;----------------------------
  8. ;-   constant definitions   -  
  9. ;---------------------------
  10.  
  11. custom=$dff000            ;base odf cvustom chips
  12. pf1_width    =    40    ;playfield 1 byte width
  13. pf1_height    =    200    ;lines height
  14. pf1_depth    =    3    ;planes depth
  15. pf1_planesize    =    pf1_width*pf1_height
  16. pf1_sizeOf    =    pf1_planesize*pf1_depth 
  17.  
  18. pf2_width    =    40    ;playfield 1 byte width
  19. pf2_height    =    200    ;lines height
  20. pf2_depth    =    3    ;planes depth
  21. pf2_planesize    =    pf1_width*pf2_height
  22. pf2_sizeOf    =    pf1_planesize*pf2_depth
  23.  
  24. mem_required    =    pf1_sizeOf+pf2_sizeOf
  25.  
  26. main:
  27.     lea    gfxLIB(pc),a1        ;library to open
  28.     moveq    #$00,d0            ;any version
  29.     callexec    OpenLibrary    ;Attempt open
  30.     move.l    d0,_gfxBase        ;store pointer
  31.     beq    Nolib_exit        ;0 pointer=no library
  32.     move.l    #mem_required,d0    ;byte size
  33.     move.l    #memf_chip+memf_clear,d1;type of memory required
  34.     callexec    AllocMem    
  35.  
  36.     move.l    d0,membase        ;store pointer
  37.     beq    nomem_exit        ;didnt get memory
  38.     bsr    plane_adresses        ;insert plain adresses
  39.     bsr    draw_squares        ;make patter to bot. plfld
  40.     bsr    fill_top_pf        ;make window in top Plfld
  41.     move.l    _gfxBase,a0        ;library base
  42.     move.l    50(a0),oldCop        ;store system copperlist
  43.     move.l    #NewCop,50(a0)        ;insert our copperlist
  44.  
  45. wait:
  46.     Callgraf    WaitTOF        ;wait 4 raster
  47.     bsr     scroll_playfield    ;pixel scroll bottom
  48.                     ;playfield.
  49.     btst    #6,$bfe001        ;Wait for LMB
  50.     bne    wait
  51.     move.l    _gfxBase,a0        ;get library base
  52.     move.l    Oldcop,50(a0)        ;restore old Copperlist
  53.  
  54. Dealloc:
  55.     move.l    membase,a1        ;deallocate memory
  56.     move.l    #mem_required,d0    
  57.     Callexec    Freemem
  58.  
  59.  
  60. NoMem_exit:
  61.     move.l    _gfxBase,a1        ;close gfx library
  62.     CallEXEC    closeLibrary
  63.  
  64.  
  65. NoLib_exit:
  66.     rts
  67.  
  68. ;----------------------------------------------------------
  69.  
  70. plane_adresses:
  71.     move.l    membase,d0        ;bottom playfield
  72.     move.l    d0,d3            ;preserve
  73.     lea    top_planes,a0        ;pointer to label in Coplist
  74.     move.l    #pf1_planeSize,d1    ;size of 1 plane
  75.     bsr    pa_main            ;insert adresses
  76.     move.l    d3,d0            ;retrieve pointer
  77.     add.l    #pf1_sizeOf,d0        ;Inc. to top Playfield.
  78.     move.l    d0,pf2_base        ;store to PF adress
  79.     lea    bottom_planes,a0    ;pointer to label in Coplist
  80.     move.l    #pf2_planesize,d1    
  81.  
  82. pa_main:
  83.     moveq    #$02,d2        ;for 3 planes both playfields.
  84.  
  85. pa_loop:
  86.     move    d0,6(a0)        ;insert low word of adress
  87.     swap    d0
  88.     move    d0,2(a0)        ;insert high word of adress
  89.     swap     d0
  90.     add.l    d1,d0            ;add plane offset
  91.     lea    8(a0),a0        ;incr past plane pointers
  92.     dbra    d2,pa_loop        ;for all planes
  93.     rts
  94.  
  95. ;-------------------------------------------------------------
  96.  
  97. draw_squares:
  98.     move.l    membase,a0        ;pointer to bot. PF
  99.     move.l    #$ff00ff00,d0        ;pattern to draw
  100.     move    #24,d2            ;do block 25 times
  101.  
  102. ds_outer:
  103.     move    #8*10-1,d3        ;10 longwords*10 lines
  104.  
  105. ds_inner:
  106.     move.l    d0,(a0)+        ;write into memory
  107.     dbra    d3,ds_inner        ;for 8 lines
  108.     not.l    d0            ;invert pattern for chequered effect
  109.     dbra    d2,ds_outer        ;for whole PF
  110.     rts
  111.  
  112. ;=====================================================
  113.  
  114. fill_top_pf:
  115.     move.l    pf2_base,a0        ;pointer to top PF
  116.     move.l    a0,a1            ;copy pointer
  117.     moveq    #-1,d0            ;fill memory pattern.
  118.     move.w    #(pf2_planesize/4)-1,d2    ;1 plane
  119.  
  120. ft_fill_loop:
  121.     move.l    d0,(a0)+        ;fill memory
  122.     dbra    d2,ft_fill_loop        ;for whole plane
  123.     lea    pf1_width*50+10(a1),a1    ;incr to mid-screen
  124.  
  125. ft_clear_outer:
  126.     moveq    #$04,d2            ;longwords to clear
  127.  
  128. ft_clear_inner:
  129.     move.l    d0,(a1)+        ;write to memory
  130.     dbra    d2,ft_clear_inner    
  131.     lea    20(a1),a1        ;add module
  132.     dbra    d1,ft_clear_outer
  133.     rts
  134.  
  135. ;================================================================
  136.  
  137. scroll_playfield:
  138.     lea    newcop,a0        ;pointer to copperlist
  139.     move.w    scroll,d0        ;scroll value
  140.     addi.w    #$01,d0            ;increment
  141.     addi.w    #$0f,d0            ;mask of unneded bits
  142.     move.w    d0,scroll        ;replace
  143.     move.w     d0,6(a0)        ;and place in relevant register
  144.     rts
  145.  
  146. ;=======================================================
  147.  
  148. gfxLib:
  149.     dc.b    "graphics.library",0
  150.     even
  151.  
  152. _gfxbase:    dc.l    0
  153. membase:    dc.l    0
  154. pf2_base:    dc.l    0
  155. oldCop:        dc.l    0
  156. scroll:        dc.w    0
  157.  
  158. ;=============================================================
  159.  
  160.     section    chipstuff,data_c
  161.  
  162. newcop:
  163.     dc.w    $0100,$6600,$0102,$0000,$0104,$0060
  164.     dc.w    $0108,$0000,$010a,$0000
  165.     dc.w    $0092,$0038,$0094,$00d0
  166.     dc.w    $008e,$2c81,$0090,$f4c0
  167.  
  168. top_planes:
  169.     dc.w    $00e0,$0000,$00e2,$0000
  170.     dc.w    $00e8,$0000,$00ea,$0000
  171.     dc.w    $00f0,$0000,$00f2,$0000
  172.  
  173. bottom_planes:
  174.     dc.w    $00e4,$0000,$00e6,$0000
  175.     dc.w    $00ec,$0000,$00ee,$0000
  176.     dc.w    $00f4,$0000,$00f4,$0000
  177.  
  178.     dc.w    $0180,$0888,$0182,$0026
  179.     dc.w    $0184,$0440,$0186,$0a66
  180.     dc.w    $0188,$06aa,$018a,$0056
  181.     dc.w    $018c,$0340,$018e,$0ddd
  182.  
  183.     dc.w    $0190,$0000,$0192,$0500
  184.     dc.w    $0194,$0600,$0196,$0a33
  185.     dc.w    $0192,$0eaa,$019a,$00a4
  186.     dc.w    $019c,$004b,$019e,$0fef
  187.  
  188.     dc.w    $ffff,$fffe
  189.  
  190.